package book;

import java.time.LocalDate;
import java.time.LocalDateTime;

public class Book implements Comparable<Book>{
    private int id;
    private String title;
    private String author;
    private LocalDate shelfDate;
    private int publishYear;
    private boolean isBorrowed;
    private int BorrowedCount;
    private String category;

    public Book(String title, String author, LocalDate shelfDate, int publishYear, String category) {
        this.title = title;
        this.author = author;
        this.shelfDate = shelfDate;
        this.publishYear = publishYear;
        this.category = category;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public LocalDate getShelfDate() {
        return shelfDate;
    }

    public void setShelfDate(LocalDate shelfDate) {
        this.shelfDate = shelfDate;
    }

    public int getPublishYear() {
        return publishYear;
    }

    public void setPublishYear(int publishYear) {
        this.publishYear = publishYear;
    }

    public boolean getIsBorrowed() {
        return isBorrowed;
    }

    public void setIsBorrowed(boolean borrowed) {
        isBorrowed = borrowed;
    }

    public int getBorrowedCount() {
        return BorrowedCount;
    }

    public void setBorrowedCount(int borrowedCount) {
        BorrowedCount = borrowedCount;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String toJson(){
        StringBuilder json = new StringBuilder();
        json.append(id).append(",");
        json.append(title).append(",");
        json.append(author).append(",");
        json.append(category).append(",");
        json.append(publishYear).append(",");
        json.append(isBorrowed).append(",");
        json.append(BorrowedCount).append(",");
        json.append(shelfDate);

        return json.toString();
    }

    @Override
    public String toString() {
        return "Book{" +
                "id=" + id +
                ", title='" + title + '\'' +
                ", author='" + author + '\'' +
                ", shelfDate=" + shelfDate +
                ", publishYear=" + publishYear +
                ", isBorrowed=" + isBorrowed +
                ", BorrowedCount=" + BorrowedCount +
                ", category='" + category + '\'' +
                '}';
    }

    @Override
    public int compareTo(Book o) {
        return o.BorrowedCount - this.BorrowedCount;
    }
}
